﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace moc.Models
{
    public static class DbInitializer
    {
        public static void Initialize(MocDbContext context)
        {
            context.Database.EnsureCreated();//创建数据库           
            if (context.AdminInfo.Any())
            {
                return;
            }
            AdminRole role = new AdminRole()
            {
                Role_name = "超级管理员",
                Product_role = true,
                Order_role = true,
                Sys_role=true,
                User_role=true
            };
            context.AdminRole.Add(role);
            context.SaveChanges();
            var roleAdmin = (from c in context.AdminRole
                             select c.Role_id).Last();
            int roleId = (int)roleAdmin;

            AdminInfo admin = new AdminInfo()
            {
                Admin_name = "admin",
                Password = "admin",
                Role_id=roleId
            };
            context.AdminInfo.Add(admin);
            context.SaveChanges();
        }
    }
}
